import { Button, Space } from 'antd'
import React, { useEffect, useState } from 'react'
import axios from 'axios'
import {useNavigate} from'react-router-dom'
import TableData from './TableData'

import Homeaction from './homeaction'
export default function Victyhome() {
  const [dk,setdk]=useState("")
  const [dkstatus,setdkstatus]=useState("")
  const navigate = useNavigate()
  const tokenname = window.localStorage.getItem("victyname")

const Testdocker=()=>{
  // 向主进程发送消息，并接收返回值

 window.electron.ipcRenderer.send("testdocker","testdocker")
 window.electron.ipcRenderer.on("dkdata",(e,data)=>{
  console.log(data)
  setdk(data)
})
 window.electron.ipcRenderer.on("dkstatus",(e,data)=>{
  console.log(data)
  setdkstatus(data)
})
}

//检测 docker是否正常
useEffect(()=>{

const timer = setInterval(()=>{
  window.electron.ipcRenderer.send("testdocker",tokenname)
  window.electron.ipcRenderer.on("dkdata",(e,data)=>{
   console.log(data)
   const victyToken = window.localStorage.getItem("victyToke")
   setdk(data)
 })
},500000)
return (()=>{
  clearInterval(timer)
})

})
//检测容器是否正常运行

useEffect(()=>{
const timer = setInterval(()=>{
  window.electron.ipcRenderer.on("dkstatus",(e,data)=>{
    console.log(data)
    setdkstatus(data)
  })

},120000)
return (()=>{
  clearInterval(timer)
})

},[])
useEffect(()=>{
  const timer= setInterval(()=>{
    Homeaction()
  },320000)
  return (()=>{
    clearInterval(timer)
  })


})

const deluser =()=>{
  window.localStorage.removeItem('victyname')
  window.localStorage.removeItem('victyToke')
  navigate("/")
  window.location.reload()
}

  return (
    //全部居中样式
    // <div  style={{display: "flex",justify-content:, "center",align-items: "center", width: "100%"}}>
      <div >
      <div><h1 style={{textAlign:"center"}}>第五城容器信息</h1></div>
      <div><TableData></TableData></div>
      <div>
        <h1 style={{textAlign:"center"}}>{dk}</h1>
      </div>
      <div>
        <h1 style={{textAlign:"center"}}>{dkstatus}</h1>
      </div>
      <div style={{display:"flex",justifyContent:"center",alignItems:"center",width:"100%"}} >
        <Space>
        <Button type="primary" onClick={Testdocker}>检测</Button>
        <Button type="primary" onClick={()=>{window.location.reload()}}>刷新页面</Button>
        <Button type="primary" onClick={deluser}>切换用户</Button>
        </Space>
      </div>
      <div>

      </div>
    </div>
  )
}
